package cn.edu.njust.alg;

public class SqrtImpl {

	public static double sqrt(double k) {
		if (k < 0)
			return Double.NaN;
		double err = 1e-15;
		double t = k;
		while (Math.abs(t - k / t) > err * t) {
			t = (t + k / t) / 2.0;
		}
		return t;
	}

	public static void main(String[] args) {
		int k=25;
		System.out.println(sqrt(k));
		Math.sqrt(10);
	}

}
